{/* LAYOUT模板 */}
	<layout name="layout"/>
{/* LAYOUT模板 */}
{/* import Js,Css */}
	<js href="__PUBLIC__/js/admin/listTable.js"/>
	<js href="__PUBLIC__/js/admin/js.util.js"/>
	<css href="__PUBLIC__/css/admin/common.css"/>
	<js href="__PUBLIC__/js/admin/js.selectzone.js"/>
	
	<css href="__PUBLIC__/css/jquery-ui.css" />
	<js href="__PUBLIC__/js/core/jquery-ui.1.10.4.js" />
	<js href="__PUBLIC__/js/core/plugins.js"/>
{/* import js,css */}
<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->

<div class="main-div">
	<form action="__URL__/send_by_user" method="post" name="theForm2" onsubmit="return validate2()">
		<table width="100%">
			<tr>
				<td class="label" align="right">按用户等级发放红包:</td>
				<td>
				<select name="rank_id">
					<option value="0">选择会员等级</option>
					<volist name="ranklist" id="rank">
						<option value="{$key}">{$rank}</option>
					</volist>
				</select>&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="validated_email" value="1">只给通过邮件验证的用户发放红包
				</td>
			</tr>
			<tr>
				<td style="text-align:center" colspan =2>
				<input type="submit" name="send_rank" value="确定发送红包" />
				</td>
			</tr>
		</table>
		<input type="hidden" name="act" value="send_by_user" />
		<input type="hidden" name="id" value="{$id}" />
	</form>
</div>

<div class="main-div">
	<form name="theForm" action="__URL__/send_by_user" method="post" onsubmit="return validate();">
		<div class="form-div">
			<img src="__PUBLIC__/image/admin/icon_search.gif" border="0" alt="SEARCH" />{$lang.keywords}
			<input type="text" name="keyword" size="30" />
			<input type="button" name="search" value="搜索" onclick="searchUser();" />
		</div>
		<div class="list-div">
			<table cellspacing='1' cellpadding='3' width="100%">
				<tr>
					<th>会员列表：</th>
					<th>操作</th>
					<th>给下列用户发放红包</th>
				</tr>
				<tr>
					<td width="45%" align="center">
						<select name="user_search[]" id="user_search" size="15" style="width:260px" ondblclick="addUser()" multiple="true">
						</select>
					</td>
					<td align="center">
						<p><input type="button" value="&gt;" onclick="addUser()"  /></p>
						<p><input type="button" value="&lt;" onclick="delUser()"  /></p>
					</td>
					<td width="45%" align="center">
						<select name="user[]" id="user" multiple="true" size="15" style="width:260px" ondblclick="delUser()">
						</select>
					</td>
				</tr>
				<tr>
					<td align="center" colspan="3">
						<input type="submit" name="send_user" value="确定发送红包"  />
					</td>
				</tr>
			</table>
		</div>
		<input type="hidden" name="id" value="{$id}" />
		<input type="hidden" name="act" value="send_by_user" />
	</form>
</div>


<script language="JavaScript">

document.forms['theForm'].elements['keyword'].focus();
onload = function(){
    // 开始检查订单
    //startCheckOrder();
}
/**
* 按用户名搜索用户
*/
function searchUser(){
	var eles = document.forms['theForm'].elements;
	/* 填充列表 */
	var keywords = Utils.trim(eles['keyword'].value);
	if (keywords != ''){
		Ajax.call('bonus.php?is_ajax=1&act=search_users', 'keywords=' + keywords, searchUserResponse, "GET", "jsON");
	}
}

function searchUserResponse(result){
	var eles = document.forms['theForm'].elements;
	eles['user_search[]'].length = 0;

	if (result.error == 0){
		for (i = 0; i < result.content.length; i++){
			var opt = document.createElement('OPTION');
			opt.value = result.content[i].user_id;
			opt.text  = result.content[i].user_name;
			eles['user_search[]'].options.add(opt);
		}
	}
}

function validate2(){
    var user_rank = document['theForm2'].elements['rank_id'].value;
    if (user_rank == 0){
        alert(user_rank_empty);
        return false;
    }
    return true;
}

var submiting = false;

function validate(){
	if(!submiting){
		var idArr = new Array();
		var dest = document.getElementById('user');
		for (var i = 0; i < dest.options.length; i++){
			dest.options[i].selected = "true";
			idArr.push(dest.options[i].value);
		}
		if (idArr.length <= 0){
			alert(user_name_empty);
			return false;
		}
		else{
			submiting = true;
			return true;
		}
	}
	else{
		alert('Submitting...');
		return false;
	}
}

function addUser(){
	var src = document.getElementById('user_search');
	var dest = document.getElementById('user');

	for (var i = 0; i < src.options.length; i++){
		if (src.options[i].selected){
			var exist = false;
			for (var j = 0; j < dest.options.length; j++){
				if (dest.options[j].value == src.options[i].value){
					exist = true;
					break;
				}
			}
			if (!exist){
				var opt = document.createElement('OPTION');
				opt.value = src.options[i].value;
				opt.text = src.options[i].text;
				dest.options.add(opt);
			}
		}
	}
}

function delUser(){
	var dest = document.getElementById('user');
	for (var i = dest.options.length - 1; i >= 0 ; i--){
		if (dest.options[i].selected){
			dest.options[i] = null;
		}
	}
}

//-->
</script>